package com.tungse.juc.collection;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class MapTest {
    public static void main(String[] args) {
//        Map<String, String> map = new HashMap<>();//多线程场景不安全
//        Map<String, String> map = Collections.synchronizedMap(new HashMap<>());
        Map<String, String> map = new ConcurrentHashMap<>();

        for (int i = 0; i < 100; i++) {
            new Thread(() -> {
                map.put(UUID.randomUUID().toString().substring(1,5), Thread.currentThread().getName());
                System.out.println(map);
            }, String.valueOf(i)).start();
        }
    }
}
